<!--  -->
<template>
    <div class=''>
        <el-button type="text"
            style="position: absolute; top: 0;left: 15px;color: black;padding: 0;margin-top: 10px;font-size: 0.37rem;font-weight: bold;color: #606266;"
            @click="ESC()">返回</el-button>
        <div style="margin-top: 15%;">
            <el-form class="NewForm" ref="form" :model="form" label-width="60px">

                <el-form-item label="销售单" style="width: 85%;">
                    <el-select v-model="form.xsNum" placeholder="请选择销售单" @change="SelVal">
                        <el-option v-for="item in form.NewArr" :key="item" :label="item" :value="item"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="车牌号" style="width: 85%;">
                    <el-input v-model="form.cpNum"></el-input>
                </el-form-item>
                <el-form-item label="提货量" style="width: 85%;">
                    <el-input v-model="form.th"></el-input>
                </el-form-item>
                <el-form-item label="物料" style="width: 85%;">
                    <el-input v-model="form.wl"></el-input>
                </el-form-item>



                <el-form-item label="件次号" style="width: 85%;margin-top: 2%;">
                    <el-input v-model="form.jcNum" style=""></el-input>
                </el-form-item>
                <div style="">
                    <el-button plain size="mini" @click="Enter()">入单</el-button>
                    <el-button plain size="mini" @click="reset()">重输件次</el-button>
                    <el-button plain size="mini" @click="cancel()">取消入单</el-button>
                    <el-button plain size="mini" @click="clear()">刷新销售单</el-button>
                </div>
                <div style="text-align: left;">
                    <span style="margin-right: 15%;">累计:</span>
                    <span>{{ form.ljnum }}件</span>
                    <span style="margin-left: 35%;">{{ form.ljt }}吨</span>
                </div>
                <div style="text-align: left;">
                    <span style="margin-right: 15%;">理论:</span>
                    <span>{{ form.llt }}吨</span>
                    <!-- <el-button style="margin-left: 5px;" plain size="mini" @click="EnterMEss()">入单信息</el-button> -->
                    <el-button style="margin: 0;margin-left: 5px;" plain size="mini" @click="Confirm()">确认发货</el-button>
                </div>

                <div style="margin-top: 5%;">
                    <div style="font-size: 22px;margin-top: 5%;color: red;">
                        先扫描件次号，再选择销售单!
                    </div>
                    <el-button plain size="medium " style="width: 30%;line-height: 2;" @click="sm()">扫码</el-button>

                </div>
            </el-form>
        </div>

    </div>
</template>

<script>
import $ from 'jquery';
import 'jquery.soap';
export default {
    name: 'PageThree',
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
        //这里存放数据
        return {
            form: {
                name: '',
                region: '',
                xsNum: '',
                NewArr: [],
                cpNum: '',
                th: '',
                wl: '',
                jcNum: '',
                ljnum: '',
                ljt: '',
                llt: ''
            },
            radio: 2
        };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
        sm() {
            this.$router.push('/scanCode')
        },
        Confirm() {
            $.soap({
                url: 'api/pdaservices/services/SaleOut?',
                method: 'ConfirmSendGoods',
                data: {
                    in0: this.form.xsNum,
                },
                success: function (res) {
                    var val = res.content.all;
                    if (val[4].innerHTML == '1') {
                        if (val[5].innerHTML == '0') {
                            alert('确认发货成功,' + val[6].innerHTML);
                        } else {
                            alert('确认发货失败,' + val[6].innerHTML)
                        }
                    } else {
                        alert('webservice报错')
                    }
                }
            })
        },
        EnterMEss() {
            this.$router.push({ path: '/PageTable2', query: { val: this.form.xsNum } })
        },
        cancel() {
            var val = this.form.jcNum.slice(1);
            var that = this;
            $.soap({
                url: 'api/pdaservices/services/SaleOut?',
                method: 'CancelOrderByJP',
                data: {
                    in0: val,
                    in1: this.form.xsNum,
                    in2: '1'
                },
                success: function (res) {
                    console.log(res);
                    $.soap({
                        url: 'api/pdaservices/services/SaleOut?',
                        method: 'GetSLInfoByPiece',
                        data: {
                            in0: that.form.xsNum,
                        },
                        success: function (res) {
                            var val = res.content.all;


                            if (val[4].innerHTML == '0') {
                                alert('无返回查询检配数量信息')
                            } else if (val[4].innerHTML == '1') {
                                alert('取消入单成功')
                                // that.form.ljnum = val[5].innerHTML
                                // that.form.ljt = val[6].innerHTML
                                // that.form.llt = val[7].innerHTML
                            } else if (val[4].innerHTML == null) {
                                alert('webservice报错，结果为空')
                            } else {
                                alert('取消入单失败')
                            }
                        }
                    })
                }
            })
        },
        reset() {
            this.form.jcNum = ''
        },
        ESC() {
            window.history.go(-1);
        },
        SelVal(val) {
            var that = this;
            $.soap({
                url: 'api/pdaservices/services/SaleOut?',
                method: 'GetJPDetailByID',
                data: {
                    in0: val,
                },
                success: function (res) {
                    var text = res.content.all;
                    for (var i = 0; i < text.length; i++) {
                        if (text[i].nodeName == "xsd:anyType") {
                            that.form.cpNum = text[text.length - 1].innerHTML.split(';')[0];
                            that.form.th = text[text.length - 1].innerHTML.split(';')[1];
                            that.form.wl = text[text.length - 1].innerHTML.split(';')[2];
                            break;
                        }
                    }
                }
            })
        },
        clear() {

            console.log(this.form.xsNum, '22');
            var that = this;
            $.soap({
                url: 'api/pdaservices/services/SaleOut?',
                method: 'GetJHDiDbyStorage',
                data: {
                    in0: this.form.xsNum,
                    in1: '1'
                },
                success: function (res) {
                    console.log(res, 'zz');
                    // var val = res.content.all;


                    that.form.th = '';
                    that.form.wl = '';
                    that.form.xsNum = '';
                    that.form.cpNum = ''
                }
            })
        },
        Enter() {
            var val = this.form.jcNum.slice(1);
            var that = this;
            $.soap({
                url: 'api/pdaservices/services/SaleOut?',
                method: 'InputOrderByJP',
                data: {
                    in0: val,
                    in1: this.form.xsNum,
                    in2: '1'
                },
                success: function (res) {

                    var text = res.content.all;
                    console.log(text, '1');

                    if (text.length == 0) {
                        alert('webservice返回结果为空，检配入单信息返回失败')
                    }
                    for (var i = 0; i < text.length; i++) {
                        if (text[i].nodeName == "xsd:anyType") {
                            if (text[i].innerHTML == '0') {
                                alert('检测入单成功')
                            } else {
                                alert(text[text.length - 1].innerHTML);
                            }

                            break;
                        }
                    }
                    $.soap({
                        url: 'api/pdaservices/services/SaleOut?',
                        method: 'GetSLInfoByPiece',
                        data: {
                            in0: that.form.xsNum,

                        },
                        success: function (res) {

                            var val = res.content.all;
                            console.log(val, '22');

                            if (val[4].innerHTML === "0") {

                                alert('入单成功')
                            } else if (val[4].innerHTML === "1") {
                                alert('无返回查询检配数量信息')
                                // that.form.ljnum = val[5].innerHTML
                                // that.form.ljt = val[6].innerHTML
                                // that.form.llt = val[7].innerHTML
                            } else if (val[4].innerHTML == null) {
                                alert('webservice报错，结果为空')
                            }
                            else {
                                alert('入单失败')
                            }
                        }
                    })
                }
            })

        }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {

    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {
        var ID = sessionStorage.getItem('LoginUser').split(',')[1];
        var arr;
        var that = this;
        this.$nextTick(() => {
            $.soap({
                url: 'api/pdaservices/services/SaleOut?',
                method: 'GetJHDiDbyStorage',
                data: {
                    in0: ID,
                    in1: '0'
                },
                success: function (res) {
                    var val = res.content.all;
                    arr = [];
                    for (var i = 0; i < val.length; i++) {
                        if (val[i].nodeName == "xsd:anyType") {
                            arr.push(val[i].innerHTML)
                        }
                    }
                    arr.shift();
                    that.form.NewArr = arr;
                }
            })

        })


        var jch = sessionStorage.getItem('jc');
        if (jch) {
            this.form.jcNum = jch
        } else {
            sessionStorage.removeItem('jc')
        }



    },

}
</script>
<style lang='scss' scoped>
form div {
    margin: 0;
}

/deep/ .el-input__inner {
    height: 30px
}



form span {
    font-size: 14px;
    color: #606266;
}

.el-select {
    width: 100%;
}
</style>